package tool

import java.io.File

import tool.Pojo._
import implicits.Implicits._
import models.Tables.DataRow
import play.api.libs.json.Json
import utils.Utils

/**
 * Created by yz on 13/7/2020
 */
trait ProjectTool {

  def long2fat(workspaceDir: File, resultDir: File) = {
    val command =
      s"""
         |Rscript ${Tool.rPath.unixPath}/long2fat.R
                       """.stripMargin
    CommandData(workspaceDir, List(command))
  }

  def long2fatResultDeal(workspaceDir: File, resultDir: File) = {
    val resultFile = new File(workspaceDir, "output.csv")
    resultFile.copyTo(new File(resultDir, "result.csv"))
  }

  def getArrayByDatas(ys: List[DataRow]) = {
    ys.map { y =>
      val basicMap = Utils.getMapByT(y) - ("otherInfo")
      val otherMap = y.otherInfo
      val finalMap = basicMap ++ otherMap
      Json.toJson(finalMap)
    }
  }

}
